<template>
	<view class="page flex-col">
		<view class="box_1 flex-col">
			<view class="group_1 flex-col">
				<view class="group_2 flex-col">
					<image class="image_2" referrerpolicy="no-referrer"
						src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/eabc0dd72cc47bac5074fe14dc44af526c20be1e.png" />
					<view class="tabs_1 flex-col">
						<!-- <u-tabs :list="tabsList" lineColor="#0055ff " :activeStyle="{
							  color: '#0055ff ',
							}" :inactiveStyle="{
							  color: '#c2c1c1',
							}" :lineWidth="30" :current="currentTab" @click="onClickTab" /> -->
						<u-tabs :list="tabsList" lineColor="#E9353E" :activeStyle="{
							  color: '#333',
							}" :inactiveStyle="{
							  color: '#c2c1c1',
							}" :lineWidth="30" :current="currentTab" @click="onClickTab" />
					</view>
					<view class="group_3 ">
						<view class="group_4 flex-col" v-for="(item, index) in looplist" :key="index"
							@click="Redemption(item)">
							<view class="box_6 flex-col">
								<image class="image_10" referrerpolicy="no-referrer" :src="item.goods_image" />
								<text class="text_52">仅剩{{item.else_stock}}件</text>
							</view>
							<view class="text_53">
								<view class="text_jifen">
									{{item.goods_name}}
								</view>
							</view>
							<view class="text-wrapper_13">
								<view class="wrapper_left">
									<text class="text_54">{{item.need_points}}</text>
									<text class="text_55">积分</text>
								</view>
								<view class="text_56">¥{{item.price}}</view>
							</view>
						</view>
					</view>

				</view>
			</view>
		</view>
	</view>
</template>
<script>
	const train = require("@/api/train/index.js");
	export default {
		data() {
			return {
				tabsList: [],
				currentTab: 0,
				constants: {},
				looplist: [],
				listQuery: { //分页
					pageNo: 1,
					pageSize: 6,
				},
				totalPage: '', //几页
				cate_id: ''
			};
		},
		onLoad() {
			this.getCate()
		},
		methods: {
			onClickTab(item) {
				this.cate_id = item.id
				this.listQuery.pageNo = 1
				this.looplist = []
				this.showCoupons()
			},
			// 列表循环
			async getCate() {
				let params = {
					project_id: getApp().globalData.projectId,
					app_id: this.$https.weixinAppId,
				}
				let res = await train.getCate(params)
				if (res.code === 1) {
					this.tabsList = res.data.result
					this.cate_id = this.tabsList[0].id
					this.showCoupons()

				}
			},
			Redemption(item) {
				uni.navigateTo({
					url: './redemption_details?id=' +
						item.id
				})
			},
			// 列表循环
			async showCoupons() {
				let that = this;
				if (this.listQuery.pageNo === 1) that.looplist = [];
				let params = {
					project_id: getApp().globalData.projectId,
					app_id: this.$https.weixinAppId,
					page: this.listQuery.pageNo,
					limit: this.listQuery.pageSize,
					cate_id: this.cate_id,
					open_id: uni.getStorageSync('openid'),
				}
				let res = await train.getProduct(params)
				if (res.code === 1) {
					// this.looplist = res.data.result.data
					that.looplist = that.looplist.concat(res.data.result.data); //将数据拼接在一起
					that.totalPage = res.data.result.last_page

				}
			},
			// 下拉刷新
			onReachBottom() {
				// uni.showLoading({
				// 	title: '加载中'
				// });
				if (this.totalPage <= this.listQuery.pageNo) {
					// uni.hideLoading();
					uni.showToast({
						title: '没有更多了',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				this.listQuery.pageNo += 1;
				this.showCoupons()
			},
		}
	};
</script>
<style lang='scss'>
	@import '../../static/css/common/common.scss';

	.page {
		position: relative;
		width: 750rpx;
		height: 100%;
		overflow: hidden;

		.box_1 {
			height: 100%;
			/* background: url(/static/lanhu_jifenzhuanqu/ps5nuv51mzloe7ybzpwod18la38bhkjjkk4278f36e6-182b-4d49-a296-e7919f1c5f46.png) 100% no-repeat; */
			background-size: 100% 100%;
			width: 750rpx;

			.group_1 {
				background-color: rgba(255, 255, 255, 1);
				width: 750rpx;
				height: 100%;



				.group_2 {
					position: relative;
					width: 750rpx;
					height: 100%;
					margin-bottom: 1rpx;

					.tabs_1 {
						width: 750rpx;
						height: 110rpx;

						/* /deep/.u-tabs {
							background-color: #fff;
					
							.u-tabs__wrapper__nav__item {
								flex: 1;
							}
					
							.u-tabs__wrapper__nav__line {
								bottom: 0;
							}
						} */

					}


					.image_2 {
						width: 690rpx;
						height: 244rpx;
						margin: 24rpx 0 0 30rpx;
					}

					.group_3 {
						/* position: relative; */
						width: 100%;
						/* height: auto; */
						height: 100%;
						margin: 0 0 10rpx 10rpx;
						/* background-color: aqua; */



						.group_4 {
							background-color: rgba(255, 255, 255, 1);
							border-radius: 10rpx;
							width: 335rpx;
							height: 459rpx;
							border: 1px solid rgba(229, 229, 229, 1);
							margin-left: 20rpx;
							margin-top: 20rpx;
							float: left;

							.box_6 {
								background-color: rgba(243, 243, 243, 1);
								border-radius: 10px 0px 0px 10px;
								width: 335rpx;
								height: 335rpx;
								border-radius: 10rpx;

								.image_10 {
									width: 230rpx;
									height: 217rpx;
									margin: 59rpx 0 0 47rpx;
								}

								.text_52 {
									width: 87rpx;
									height: 23rpx;
									overflow-wrap: break-word;
									color: rgba(190, 190, 190, 1);
									font-size: 24rpx;
									font-family: PingFang-SC-Regular;
									font-weight: NaN;
									text-align: left;
									white-space: nowrap;
									line-height: 39rpx;
									margin: 17rpx 0 19rpx 227rpx;
								}
							}

							.text_53 {
								width: 100%;
								height: 60rpx;
								margin: 18rpx 0 0 20rpx;
								
								.text_jifen{
									color: rgba(51, 51, 51, 1);
									width: 300rpx;
									line-height: 28rpx;
									font-size: 28rpx;
									white-space: nowrap;
									overflow: hidden;
									text-overflow: ellipsis;
								}
							}

							.text-wrapper_13 {
								width: 330rpx;
								height: 50rpx;
								font-weight: 500;
								line-height: 36rpx;
								/* background-color: aqua; */
								margin-top: 36rpx;

								.wrapper_left {
									float: left;
									margin-left: 20rpx;

									.text_54 {
										/* width: 117rpx;
										height: 30rpx; */
										color: rgba(246, 32, 32, 1);
										font-size: 36rpx;
										font-weight: 500;
										line-height: 36rpx;
									}

									.text_55 {
										/* width: 50rpx;
										height: 30rpx; */
										color: rgba(246, 32, 32, 1);
										font-size: 24rpx;
										font-weight: 500;
										line-height: 24rpx;
									}
								}


								.text_56 {
									width: 117rpx;
									height: 50rpx;
									color: rgba(156, 156, 156, 1.0);
									font-size: 24rpx;
									font-weight: 500;
									line-height: 50rpx;
									float: right;
									text-decoration: line-through;
									text-align: right;
								}

							}
						}

					}
				}
			}
		}
	}
</style>
